var editSec = null;
var editType = null;
$(function(){
	loadData();
});

function loadData() {
	var opentParent = frame.window.getOpenParent();
	editType = opentParent.editType;
	if(editType && editType=="new"){
		
	} else {
		editSec = opentParent.$('#dg').datagrid("getSelected");
		$.post("./modeldetail.json", editSec, function(data) {
			$("#ff").form("load", data.quantModel);
			$("#dg").datagrid("loadData", data.modelParams);
		});
	}
}

function click_back(){
	frame.window.closeWindow();
}


function click_save_model(){
	var a=$("#ff").form('validate');
	if(!a){
		return;
	}
	editSec = $("#ff").form("getData");
	$.post("./modelsave.json", editSec, function(data) {
		if (data.sucesse == true) {
			loadData();
		}
	});
}

function click_delete_model() {
	if (editType && editType == "new") {
		frame.window.closeWindow();
	} else {
		$.messager.confirm('确认', '您确认想要删除模型吗？',
			function(r) {
				if (r) {
					deleteModel();
				}
			}
		);
	}
}

function deleteModel() {
	editSec = $("#ff").form("getData");
	$.post("./modeldelete.json",
		editSec,
		function(data) {
			if (data.sucesse == true) {
				frame.window.getOpenParent().$('#dg').datagrid("reload");
				frame.window.closeWindow();
			}
		}
	);
}

function click_add_model_param() {
	$('#dg').edatagrid('addRow', {
		row : {
			modelCode : editSec.code
		}
	});
}

function dg_onSave(index, row) {
	loadData();
}



